aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/[username]/(profile)/notes/new/+page.svelte
blob: 445890a3c38eaf9438cc5ee4106deea691fe39d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<script>
  import { goto } from "$app/navigation";
  import { send, sign } from "$lib/nostr";
  import { t } from "$lib/translations";
  import { focus } from "$lib/utils";

  let { data } = $props();
  let { user } = $derived(data);
  let { pubkey } = $derived(user);
  let content = $state();

  let submit = async (e) => {
    try {
      e.preventDefault();

      let event = {
        kind: 1,
        content,
        created_at: Math.round(Date.now() / 1000),
        tags: [],
      };

      event = await sign(event, user);
      await send(event);

      goto(`/${user.username}/notes`);
    } catch (e) {
      console.log(e);
    }
  };
</script>

<div class="container px-4 max-w-xl mx-auto space-y-5">
  <form method="POST" class="space-y-2 text-xl" onsubmit={submit}>
    <textarea use:focus bind:value={content} placeholder={$t("notes.contents")}
    ></textarea>
    <button type="submit" class="btn btn-accent">
      {$t("payments.submit")}</button
    >
  </form>
</div>